
template = '''# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This source file is part of the Cangjie project, licensed under Apache-2.0
# with Runtime Library Exception.
# 
# See https://cangjie-lang.cn/pages/LICENSE for license information.

/*
  @Name:         03_01_a02_%03d

  @Assertion:    3.1(2) Keywords, variables, functions, types (including class, interface, struct, enum, 
                  and type alias), packages and modules in the Cangjie programming language share 
                  the same name spaces.
                  
  @Description:  Сheck that entity `%s` and keyword `%s` have the same namespace.

  @Mode:         compileonly

  @Negative:     yes

  @Structure:    single

  @Comment:      Auto-generated by gen_negative_tests_3_1_2.py

*/

%s

main() {}
'''
# keywords (without contextual keywords)
keywords = ['as', 'break', 'Bool',
            'case', 'catch', 'class',
            'continue', 'Rune', 'do',
            'else', 'enum', 'extend',
            'false', 'finally', 'for',
            'foreign', 'from', 'func',
            'Float16', 'Float32', 'Float64',
            'if', 'import', 'in',
            'init', 'interface', 'is',
            'Int8', 'Int16', 'Int32',
            'Int64', 'IntNative', 'let',
            'macro', 'match', 'mut',
            'main', 'Nothing', 'operator',
            'package', 'prop', 'quote',
            'return', 'spawn', 'struct',
            'static', 'super', 'synchronized',
            'this', 'throw', 'true',
            'try', 'type', 'This',
            'unsafe', 'UInt8', 'UInt16',
            'UInt32', 'UInt64', 'UIntNative',
            'Unit', 'var', 'where',
            'while'] 

entities = ['let', 'var', 'func', 
            'class', 'interface', 'struct', 
            'enum', 'type', 'package', 
            'module']

entities_name = {
  'let':'immutable variable',
  'var':'mutable variable',
  'func':'function',
  'class':'class',
  'interface':'interface',
  'struct':'struct',
  'enum':'enum',
  'type':'type alias',
  'package':'package',
  'module':'module',
}

entity_template = {
  'let':'let %s = 0',
  'var':'var %s = 1',
  'func':'func %s() {}',
  'class':'class %s {}',
  'interface':'interface %s {}',
  'struct':'struct %s {}',
  'enum':'enum %s { x }',
  'type':'type %s = (Int64, Int64)',
  'package':'package %s',
  'module':'from %s import pkg.xxx'
}

def main():
  '''Generating tests for assert 3.1(2)'''
  start_generation = 2  # offset so as not to overwrite manual tests
  i = start_generation
  for entity in entities:
    for key in keywords:
      with open(f'./test_a02_{i:03d}.cj', 'w', encoding='utf-8') as f:
        init_template = entity_template.get(entity) % key
        f.write(template % (i, entities_name.get(entity), key, init_template))
        i+= 1

  print(f'Total tests generated: {i - start_generation}')

if __name__ == '__main__':
  main()